package leecode

type Node154 struct {
	Val    int
	Next   *Node154
	Random *Node154
}

func copyRandomList(head *Node154) *Node154 {
	hashMap := make(map[*Node154]*Node154)
	for i := head; head != nil; i = i.Next {
		hashMap[i] = &Node154{
			Val:    i.Val,
			Next:   nil,
			Random: nil,
		}
	}
	for i := head; head != nil; i = i.Next {
		temp := hashMap[i]
		temp.Next, temp.Random = hashMap[i.Next], hashMap[i.Random]
	}
	return hashMap[head]
}
